package com.sc.VenusQueryBeta.ui.activites.login;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;

import com.hengjun.kingstar.sdk.base.BasePresenter;
import com.hengjun.kingstar.sdk.base.activity.BaseMVPCompatActivity;
import com.hengjun.kingstar.sdk.utils.LogUtils;
import com.hengjun.kingstar.sdk.utils.SpUtils;
import com.hengjun.kingstar.sdk.utils.ToastUtils;
import com.sc.VenusQueryBeta.R;
import com.sc.VenusQueryBeta.constant.Constants;
import com.sc.VenusQueryBeta.contract.login.ForgotNextContract;
import com.sc.VenusQueryBeta.model.bean.login.ChangePwdBean;
import com.sc.VenusQueryBeta.presenter.login.ForgotNextPresenter;

import butterknife.BindView;
import butterknife.OnClick;

public class ForgotNextActivity extends BaseMVPCompatActivity<ForgotNextContract.ForgotNextPresenter> implements ForgotNextContract.IForgotNextView {

    @BindView(R.id.changepassword_back)
    ImageButton changepasswordBack;
    @BindView(R.id.new_password)
    EditText newPassword;
    @BindView(R.id.comfirm_new_password)
    EditText comfirmNewPassword;
    @BindView(R.id.btn_change_password)
    Button btnChangePassword;
    private String iphone;
    @NonNull
    @Override
    public BasePresenter initPresenter() {
        return ForgotNextPresenter.newInstance();
    }

    @Override
    public void showChangePwdSuccess(ChangePwdBean changePwdBean) {
        LogUtils.e("参数值    "+changePwdBean.getId()+"          "+changePwdBean.getPassword());
        // SpUtils.putString(MyApplication.app,Constants.IPHONE,changePwdBean.getPassword());
        finish();
    }

    @Override
    public void showNetworkError() {
        ToastUtils.showToast("你出错了");
        hideProgressDialog();
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_forgot_next;
    }

    @OnClick({R.id.changepassword_back, R.id.btn_change_password})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.changepassword_back:
              finish();
                break;
            case R.id.btn_change_password:
                if (!newPassword.getText().toString().trim().equals("") && !comfirmNewPassword.getText().toString().trim().equals("")) {//密码不能为空
                    if (comfirmNewPassword.getText().toString().trim().equals(newPassword.getText().toString())) {//密码一致
                        iphone  = SpUtils.getString(this, Constants.IPHONE,"");
                        mPresenter.forgot(iphone,newPassword.getText().toString());
                        LogUtils.e("iphoe= = = = = ="+iphone);
                    } else {
                        ToastUtils.showToast(getString(R.string.nosame));
                    }
                }else {
                    ToastUtils.showToast(getString(R.string.mimakong));
                }
                break;
        }
    }
}
